package com.icss.service.impl;

import com.icss.dao.UserDao;
import com.icss.model.User;
import com.icss.service.UserService;

public class UserServiceImpl implements UserService {

	@Override
	public User findByUserName(String name) {
		String sql="select id,name,pass,tel,type,time from user where name = ?";
		if(UserDao.query(sql, name).size() > 0) {
			return UserDao.query(sql, name).get(0);
		}else {
			return null;
		}
		
	}

	@Override
	public boolean reg(User u) {
		String sql="insert into user values(default,?,?,?,?,default)";
		return UserDao.modify(sql, u.getName(),u.getPass(),u.getTel(),u.getType());
	}

	@Override
	public User login(String name, String pass) {
		String sql = "select id,name,pass,tel,type,time from user where name = ? and pass = ?";
		if(UserDao.query(sql, name,pass).size() > 0) {
			return UserDao.query(sql, name,pass).get(0);
		}else {
			return null;
		}
	}

	@Override
	public User findByUserTel(String tel) {
		String sql="select id,name,pass,tel,type,time from user where tel = ?";
		if(UserDao.query(sql, tel).size() > 0) {
			return UserDao.query(sql, tel).get(0);
		}else {
			return null;
		}
	}

}
